home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / CIncludes / OSUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  13.6 KB  |  560 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        OSUtils.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __OSUTILS__
  18. #define __OSUTILS__
  19.  
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. /*    #include <ConditionalMacros.h>                                */
  25.  
  26. #ifndef __MIXEDMODE__
  27. #include <MixedMode.h>
  28. #endif
  29.  
  30. #ifndef __MEMORY__
  31. #include <Memory.h>
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #if GENERATINGPOWERPC
  39. #pragma options align=mac68k
  40. #endif
  41.  
  42. #ifdef __CFM68K__
  43. #pragma lib_export on
  44. #endif
  45.  
  46.  
  47. enum {
  48.     useFree                        = 0,
  49.     useATalk                    = 1,
  50.     useAsync                    = 2,
  51.     useExtClk                    = 3,                            /*Externally clocked*/
  52.     useMIDI                        = 4,
  53. /* Environs Equates */
  54.     curSysEnvVers                = 2,                            /*Updated to equal latest SysEnvirons version*/
  55. /* Machine Types */
  56.     envMac                        = -1,
  57.     envXL                        = -2,
  58.     envMachUnknown                = 0,
  59.     env512KE                    = 1,
  60.     envMacPlus                    = 2,
  61.     envSE                        = 3,
  62.     envMacII                    = 4,
  63.     envMacIIx                    = 5,
  64.     envMacIIcx                    = 6,
  65.     envSE30                        = 7,
  66.     envPortable                    = 8,
  67.     envMacIIci                    = 9,
  68.     envMacIIfx                    = 11,
  69. /* CPU types */
  70.     envCPUUnknown                = 0
  71. };
  72.  
  73. enum {
  74.     env68000                    = 1,
  75.     env68010                    = 2,
  76.     env68020                    = 3,
  77.     env68030                    = 4,
  78.     env68040                    = 5,
  79. /* Keyboard types */
  80.     envUnknownKbd                = 0,
  81.     envMacKbd                    = 1,
  82.     envMacAndPad                = 2,
  83.     envMacPlusKbd                = 3,
  84.     envAExtendKbd                = 4,
  85.     envStandADBKbd                = 5,
  86.     envPrtblADBKbd                = 6,
  87.     envPrtblISOKbd                = 7,
  88.     envStdISOADBKbd                = 8,
  89.     envExtISOADBKbd                = 9,
  90.     false32b                    = 0,                            /*24 bit addressing error*/
  91.     true32b                        = 1,                            /*32 bit addressing error*/
  92. /* result types for RelString Call */
  93.     sortsBefore                    = -1,                            /*first string < second string*/
  94.     sortsEqual                    = 0,                            /*first string = second string*/
  95.     sortsAfter                    = 1                                /*first string > second string*/
  96. };
  97.  
  98. enum {
  99. /* Toggle results */
  100.     toggleUndefined                = 0,
  101.     toggleOK                    = 1,
  102.     toggleBadField                = 2,
  103.     toggleBadDelta                = 3,
  104.     toggleBadChar                = 4,
  105.     toggleUnknown                = 5,
  106.     toggleBadNum                = 6,
  107.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  108.     toggleErr3                    = 7,
  109.     toggleErr4                    = 8,
  110.     toggleErr5                    = 9,
  111. /* Date equates */
  112.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  113.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  114.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  115.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  116.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  117.     validDateFields                = -1,
  118.     maxDateField                = 10,
  119.     eraMask                        = 0x0001,
  120.     yearMask                    = 0x0002,
  121.     monthMask                    = 0x0004,
  122.     dayMask                        = 0x0008,
  123.     hourMask                    = 0x0010,
  124.     minuteMask                    = 0x0020,
  125.     secondMask                    = 0x0040,
  126.     dayOfWeekMask                = 0x0080,
  127.     dayOfYearMask                = 0x0100,
  128.     weekOfYearMask                = 0x0200,
  129.     pmMask                        = 0x0400,
  130.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  131. };
  132.  
  133. enum {
  134.     eraField,
  135.     yearField,
  136.     monthField,
  137.     dayField,
  138.     hourField,
  139.     minuteField,
  140.     secondField,
  141.     dayOfWeekField,
  142.     dayOfYearField,
  143.     weekOfYearField,
  144.     pmField,
  145.     res1Field,
  146.     res2Field,
  147.     res3Field
  148. };
  149.  
  150. typedef SignedByte LongDateField;
  151.  
  152.  
  153. enum {
  154.     dummyType,
  155.     vType,
  156.     ioQType,
  157.     drvQType,
  158.     evType,
  159.     fsQType,
  160.     sIQType,
  161.     dtQType,
  162.     nmType
  163. };
  164.  
  165. typedef SignedByte QTypes;
  166.  
  167.  
  168. enum {
  169.     OSTrap,
  170.     ToolTrap
  171. };
  172.  
  173. typedef SignedByte TrapType;
  174.  
  175. struct SysParmType {
  176.     UInt8                            valid;
  177.     UInt8                            aTalkA;
  178.     UInt8                            aTalkB;
  179.     UInt8                            config;
  180.     short                            portA;
  181.     short                            portB;
  182.     long                            alarm;
  183.     short                            font;
  184.     short                            kbdPrint;
  185.     short                            volClik;
  186.     short                            misc;
  187. };
  188. typedef struct SysParmType SysParmType, *SysPPtr;
  189.  
  190. typedef struct QElem QElem;
  191.  
  192. typedef QElem *QElemPtr;
  193.  
  194. struct QElem {
  195.     QElemPtr                        qLink;
  196.     short                            qType;
  197.     short                            qData[1];
  198. };
  199. typedef struct QHdr QHdr;
  200.  
  201. typedef QHdr *QHdrPtr;
  202.  
  203. struct QHdr {
  204.     short                            qFlags;
  205.     QElemPtr                        qHead;
  206.     QElemPtr                        qTail;
  207. };
  208. /*
  209.         DeferredTaskProcPtr uses register based parameters on the 68k and cannot
  210.         be written in or called from a high-level language without the help of
  211.         mixed mode or assembly glue.
  212.  
  213.         In:
  214.          => dtParam         A1.L
  215. */
  216.  
  217. #if GENERATINGCFM
  218. typedef UniversalProcPtr DeferredTaskUPP;
  219. #else
  220. typedef Register68kProcPtr DeferredTaskUPP;
  221. #endif
  222.  
  223. struct DeferredTask {
  224.     QElemPtr                        qLink;
  225.     short                            qType;
  226.     short                            dtFlags;
  227.     DeferredTaskUPP                    dtAddr;
  228.     long                            dtParam;
  229.     long                            dtReserved;
  230. };
  231. typedef struct DeferredTask DeferredTask, *DeferredTaskPtr;
  232.  
  233. struct SysEnvRec {
  234.     short                            environsVersion;
  235.     short                            machineType;
  236.     short                            systemVersion;
  237.     short                            processor;
  238.     Boolean                            hasFPU;
  239.     Boolean                            hasColorQD;
  240.     short                            keyBoardType;
  241.     short                            atDrvrVersNum;
  242.     short                            sysVRefNum;
  243. };
  244. typedef struct SysEnvRec SysEnvRec;
  245.  
  246. struct MachineLocation {
  247.     Fract                            latitude;
  248.     Fract                            longitude;
  249.     union {
  250.         SInt8                            dlsDelta;                /*signed byte; daylight savings delta*/
  251.         long                            gmtDelta;                /*must mask - see documentation*/
  252.     } u;
  253. };
  254.  
  255. typedef struct MachineLocation MachineLocation;
  256.  
  257. struct DateTimeRec {
  258.     short                            year;
  259.     short                            month;
  260.     short                            day;
  261.     short                            hour;
  262.     short                            minute;
  263.     short                            second;
  264.     short                            dayOfWeek;
  265. };
  266. typedef struct DateTimeRec DateTimeRec;
  267.  
  268. typedef wide LongDateTime;
  269.  
  270. union LongDateCvt {
  271.     wide                            c;
  272.         struct {
  273.             UInt32                            lHigh;
  274.             UInt32                            lLow;
  275.         }                            hl;
  276. };
  277. typedef union LongDateCvt LongDateCvt;
  278.  
  279. union LongDateRec {
  280.         struct {
  281.             short                            era;
  282.             short                            year;
  283.             short                            month;
  284.             short                            day;
  285.             short                            hour;
  286.             short                            minute;
  287.             short                            second;
  288.             short                            dayOfWeek;
  289.             short                            dayOfYear;
  290.             short                            weekOfYear;
  291.             short                            pm;
  292.             short                            res1;
  293.             short                            res2;
  294.             short                            res3;
  295.         }                            ld;
  296.     short                            list[14];                    /*Index by LongDateField!*/
  297.         struct {
  298.             short                            eraAlt;
  299.             DateTimeRec                        oldDate;
  300.         }                            od;
  301. };
  302. typedef union LongDateRec LongDateRec;
  303.  
  304. typedef SInt8 DateDelta;
  305.  
  306. struct TogglePB {
  307.     long                            togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  308.     ResType                            amChars;                    /*from 'itl0', but uppercased*/
  309.     ResType                            pmChars;                    /*from 'itl0', but uppercased*/
  310.     long                            reserved[4];
  311. };
  312. typedef struct TogglePB TogglePB;
  313.  
  314. typedef short ToggleResults;
  315.  
  316. enum {
  317.     uppDeferredTaskProcInfo = kRegisterBased
  318.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(long)))
  319. };
  320.  
  321. #if GENERATINGCFM
  322. #define NewDeferredTaskProc(userRoutine)        \
  323.         (DeferredTaskUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDeferredTaskProcInfo, GetCurrentArchitecture())
  324. #else
  325. #define NewDeferredTaskProc(userRoutine)        \
  326.         ((DeferredTaskUPP) (userRoutine))
  327. #endif
  328.  
  329. #if GENERATINGCFM
  330. #define CallDeferredTaskProc(userRoutine, dtParam)        \
  331.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDeferredTaskProcInfo, (dtParam))
  332. #else
  333. /* (*DeferredTaskProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  334. #endif
  335.  
  336. extern pascal void LongDateToSeconds(const LongDateRec *lDate, LongDateTime *lSecs)
  337.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  338. extern pascal void LongSecondsToDate(LongDateTime *lSecs, LongDateRec *lDate)
  339.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  340. extern pascal ToggleResults ToggleDate(LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch, const TogglePB *params)
  341.  FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  342. extern pascal short ValidDate(const LongDateRec *vDate, long flags, LongDateTime *newSecs)
  343.  FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  344. extern pascal Boolean IsMetric(void)
  345.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA9ED);
  346. extern pascal SysPPtr GetSysPPtr(void)
  347.  THREEWORDINLINE(0x2EBC, 0x0000, 0x01F8);
  348.  
  349. #if !GENERATINGCFM
  350. #pragma parameter __D0 ReadDateTime(__A0)
  351. #endif
  352. extern pascal OSErr ReadDateTime(unsigned long *time)
  353.  ONEWORDINLINE(0xA039);
  354.  
  355. #if !GENERATINGCFM
  356. #pragma parameter GetDateTime(__A0)
  357. #endif
  358. extern pascal void GetDateTime(unsigned long *secs)
  359.  TWOWORDINLINE(0x20B8, 0x020C);
  360.  
  361. #if !GENERATINGCFM
  362. #pragma parameter __D0 SetDateTime(__D0)
  363. #endif
  364. extern pascal OSErr SetDateTime(unsigned long time)
  365.  ONEWORDINLINE(0xA03A);
  366.  
  367. #if !GENERATINGCFM
  368. #pragma parameter SetTime(__A0)
  369. #endif
  370. extern pascal void SetTime(const DateTimeRec *d)
  371.  TWOWORDINLINE(0xA9C7, 0xA03A);
  372.  
  373. #if !GENERATINGCFM
  374. #pragma parameter GetTime(__A0)
  375. #endif
  376. extern pascal void GetTime(DateTimeRec *d)
  377.  THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  378. extern pascal void DateToSeconds(const DateTimeRec *d, unsigned long *secs);
  379.  
  380. #if !GENERATINGCFM
  381. #pragma parameter SecondsToDate(__D0, __A0)
  382. #endif
  383. extern pascal void SecondsToDate(unsigned long secs, DateTimeRec *d)
  384.  ONEWORDINLINE(0xA9C6);
  385. extern pascal void SysBeep(short duration)
  386.  ONEWORDINLINE(0xA9C8);
  387.  
  388. #if !GENERATINGCFM
  389. #pragma parameter __D0 DTInstall(__A0)
  390. #endif
  391. extern pascal OSErr DTInstall(DeferredTaskPtr dtTaskPtr)
  392.  ONEWORDINLINE(0xA082);
  393. extern pascal SInt8 GetMMUMode( void )
  394.     TWOWORDINLINE( 0x1EB8, 0x0CB2 ); /* MOVE.B $0CB2,(SP) */
  395. #if GENERATING68K
  396.  
  397. #if !GENERATINGCFM
  398. #pragma parameter SwapMMUMode(__A0)
  399. #endif
  400. extern pascal void SwapMMUMode(SInt8 *mode)
  401.  THREEWORDINLINE(0x1010, 0xA05D, 0x1080);
  402. #else
  403. #define SwapMMUMode(x) (*(SInt8*)(x) = true32b)
  404. #endif
  405. #if SystemSixOrLater
  406.  
  407. #if !GENERATINGCFM
  408. #pragma parameter __D0 SysEnvirons(__D0, __A0)
  409. #endif
  410. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld)
  411.  ONEWORDINLINE(0xA090);
  412. #else
  413. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld);
  414. #endif
  415.  
  416. #if !GENERATINGCFM
  417. #pragma parameter Delay(__A0, __A1)
  418. #endif
  419. extern pascal void Delay(long numTicks, long *finalTicks)
  420.  TWOWORDINLINE(0xA03B, 0x2280);
  421. /*
  422.     GetTrapAddress and SetTrapAddress are obsolete and should not
  423.     be used. Always use NGetTrapAddress and NSetTrapAddress instead.
  424.     The old routines will not be supported for PowerPC apps.
  425. */
  426. #if OLDROUTINENAMES && !GENERATINGCFM
  427.  
  428. #if !GENERATINGCFM
  429. #pragma parameter __A0 GetTrapAddress(__D0)
  430. #endif
  431. extern pascal UniversalProcPtr GetTrapAddress(short trapNum)
  432.  ONEWORDINLINE(0xA146);
  433.  
  434. #if !GENERATINGCFM
  435. #pragma parameter SetTrapAddress(__A0, __D0)
  436. #endif
  437. extern pascal void SetTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  438.  ONEWORDINLINE(0xA047);
  439. #endif
  440. extern pascal UniversalProcPtr NGetTrapAddress(short trapNum, TrapType tTyp);
  441. extern pascal void NSetTrapAddress(UniversalProcPtr trapAddr, short trapNum, TrapType tTyp);
  442.  
  443. #if !GENERATINGCFM
  444. #pragma parameter __A0 GetOSTrapAddress(__D0)
  445. #endif
  446. extern pascal UniversalProcPtr GetOSTrapAddress(short trapNum)
  447.  ONEWORDINLINE(0xA346);
  448.  
  449. #if !GENERATINGCFM
  450. #pragma parameter SetOSTrapAddress(__A0, __D0)
  451. #endif
  452. extern pascal void SetOSTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  453.  ONEWORDINLINE(0xA247);
  454.  
  455. #if !GENERATINGCFM
  456. #pragma parameter __A0 GetToolTrapAddress(__D0)
  457. #endif
  458. extern pascal UniversalProcPtr GetToolTrapAddress(short trapNum)
  459.  ONEWORDINLINE(0xA746);
  460.  
  461. #if !GENERATINGCFM
  462. #pragma parameter SetToolTrapAddress(__A0, __D0)
  463. #endif
  464. extern pascal void SetToolTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  465.  ONEWORDINLINE(0xA647);
  466.  
  467. #if !GENERATINGCFM
  468. #pragma parameter __A0 GetToolboxTrapAddress(__D0)
  469. #endif
  470. extern pascal UniversalProcPtr GetToolboxTrapAddress(short trapNum)
  471.  ONEWORDINLINE(0xA746);
  472.  
  473. #if !GENERATINGCFM
  474. #pragma parameter SetToolboxTrapAddress(__A0, __D0)
  475. #endif
  476. extern pascal void SetToolboxTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  477.  ONEWORDINLINE(0xA647);
  478. extern pascal OSErr WriteParam(void);
  479.  
  480. #if !GENERATINGCFM
  481. #pragma parameter Enqueue(__A0, __A1)
  482. #endif
  483. extern pascal void Enqueue(QElemPtr qElement, QHdrPtr qHeader)
  484.  ONEWORDINLINE(0xA96F);
  485.  
  486. #if !GENERATINGCFM
  487. #pragma parameter __D0 Dequeue(__A0, __A1)
  488. #endif
  489. extern pascal OSErr Dequeue(QElemPtr qElement, QHdrPtr qHeader)
  490.  ONEWORDINLINE(0xA96E);
  491. extern long SetCurrentA5(void)
  492.  THREEWORDINLINE(0x200D, 0x2A78, 0x0904);
  493.  
  494. #if !GENERATINGCFM
  495. #pragma parameter __D0 SetA5(__D0)
  496. #endif
  497. extern long SetA5(long newA5)
  498.  ONEWORDINLINE(0xC18D);
  499. #if !SystemSevenOrLater
  500. extern pascal void Environs(short *rom, short *machine);
  501. #endif
  502.  
  503. #if !GENERATINGCFM
  504. #pragma parameter __D0 InitUtil
  505. #endif
  506. extern pascal OSErr InitUtil(void)
  507.  ONEWORDINLINE(0xA03F);
  508. #if GENERATING68K
  509. extern pascal Boolean SwapInstructionCache(Boolean cacheEnable);
  510. extern pascal void FlushInstructionCache(void)
  511.  TWOWORDINLINE(0x7001, 0xA098);
  512. extern pascal Boolean SwapDataCache(Boolean cacheEnable);
  513. extern pascal void FlushDataCache(void)
  514.  TWOWORDINLINE(0x7003, 0xA098);
  515. extern pascal void FlushCodeCache(void)
  516.  ONEWORDINLINE(0xA0BD);
  517.  
  518. #if !GENERATINGCFM
  519. #pragma parameter FlushCodeCacheRange(__A0, __A1)
  520. #endif
  521. extern pascal void FlushCodeCacheRange(void *address, unsigned long count)
  522.  TWOWORDINLINE(0x7009, 0xA098);
  523. #endif
  524.  
  525. #if !GENERATINGCFM
  526. #pragma parameter ReadLocation(__A0)
  527. #endif
  528. extern pascal void ReadLocation(MachineLocation *loc)
  529.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA051);
  530.  
  531. #if !GENERATINGCFM
  532. #pragma parameter WriteLocation(__A0)
  533. #endif
  534. extern pascal void WriteLocation(const MachineLocation *loc)
  535.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA052);
  536. #if GENERATINGPOWERPC
  537. extern pascal UniversalProcPtr *GetTrapVector(short trapNumber);
  538. #endif
  539. #if OLDROUTINENAMES
  540. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  541. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  542. #define IUMetric() IsMetric()
  543. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  544. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  545. #endif
  546.  
  547. #ifdef __CFM68K__
  548. #pragma lib_export off
  549. #endif
  550.  
  551. #if GENERATINGPOWERPC
  552. #pragma options align=reset
  553. #endif
  554.  
  555. #ifdef __cplusplus
  556. }
  557. #endif
  558.  
  559. #endif /* __OSUTILS__ */
  560.